using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.ComponentModel.Design;

namespace LeisureCenter.Controls
{
    [Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
    public partial class Panel : UserControl
    {
        public Panel()
        {
            InitializeComponent();
            Padding = new Padding(5);
        }

        private Color fillColor = SystemColors.Window;
        public Color FillColor { get { return fillColor; } set { fillColor = value; } }

        public static void FillRoundRect(Graphics graphics, Rectangle rect, Brush brush)
        {
            Pen pen = new Pen(brush);
            Point from = new Point();
            Point to = new Point();

            if (rect.Width > 3)
            {
                from.X = rect.Left + 3; from.Y = rect.Top; to.X = rect.Right - 4; to.Y = rect.Top;
                graphics.DrawLine(pen, from, to);
                from.Y = rect.Bottom - 1; to.Y = rect.Bottom - 1;
                graphics.DrawLine(pen, from, to);
            }
            from.X = rect.Left; from.Y = rect.Top + 3; to.X = rect.Left; to.Y = rect.Bottom - 4;
            graphics.DrawLine(pen, from, to);
            from.X = rect.Right - 1; to.X = rect.Right - 1;
            graphics.DrawLine(pen, from, to);

            rect.Inflate(-1, -1);
            graphics.FillRectangle(brush, rect);
        }

        public static void DrawRoundRect(Graphics graphics, Rectangle rect, Pen pen)
        {
            Point from = new Point();
            Point to = new Point();

            from.X = rect.Left + 3; from.Y = rect.Top; to.X = rect.Right - 3; to.Y = rect.Top;
            graphics.DrawLine(pen, from, to);
            from.Y = rect.Bottom; to.Y = rect.Bottom;
            graphics.DrawLine(pen, from, to);
            from.X = rect.Left; from.Y = rect.Top + 3; to.X = rect.Left; to.Y = rect.Bottom - 3;
            graphics.DrawLine(pen, from, to);
            from.X = rect.Right; to.X = rect.Right;
            graphics.DrawLine(pen, from, to);

            rect.Inflate(-1, -1);
            graphics.DrawRectangle(pen, rect);

            from.X = rect.Left + 1; from.Y = rect.Top + 1; to = from; to.X++;
            graphics.DrawLine(pen, from, to);
            from.X = rect.Right - 1; to = from; to.X++;
            graphics.DrawLine(pen, from, to);
            from.X = rect.Left + 1; from.Y = rect.Bottom - 1; to = from; to.X++;
            graphics.DrawLine(pen, from, to);
            from.X = rect.Right - 1; to = from; to.X++;
            graphics.DrawLine(pen, from, to);
        }

        private void Panel_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.HighSpeed;
            Rectangle rect = ClientRectangle;
            rect.Inflate(-2, -2);
            FillRoundRect(e.Graphics, rect, new SolidBrush(fillColor));
            //RoundedRectangle roundRect = new RoundedRectangle(rect, RoundedCorner.All, 4);
            //e.Graphics.FillPath(new SolidBrush(fillColor), roundRect.ToGraphicsPath());
        }
    }
}
